/**
 * Created by Administrator on 2016/12/19.
 */
$(function(){
    img_code();
    //var type = GetQueryString("type")

    //点击图形验证码变换
    $("#vCode1").click(function(){
        img_code();
    })
    //获取验证码
    $('#vcode_btn').click(function(){
    	var mobile_reg = new RegExp(/^1[3-9]\d{9}$/);
    	var mobile = $("#tel").val();
        if(!mobile){
            showTips('请输入手机号！');
            return;
        };
        if(!mobile_reg.test(mobile)){
            showTips('手机号格式不正确！');
            return;
        };
        var key = "mdi1f84h60gj68e3hdkgt74gg13``》《《《《*&&*****./,..,y";
    	var mobileEncrypt = des (key, mobile, 1, 0);
    	console.info('mobileEncrypt:', mobileEncrypt);  
        send_code(this,'#tel',1,'1',mobileEncrypt,3);
    });
    //提交
    $(".submit").click(function(){
        //code1 = getCode().code;
        var mobile_reg = new RegExp(/^1[3-9]\d{9}$/);
        if(!$("#tel").val()){
            showTips('请输入手机号！');
            return;
        };
        if(!mobile_reg.test($('#tel').val())){
            showTips('手机号格式不正确！');
            return;
        };
        if($('#code').val()==""){
            showTips('请输入验证码！');
            return;
        }
        if($('#code_dx').val()==""){
            showTips('请输入短信验证码！');
            return;
        }
        var pwd_reg = new RegExp(/^[0-9a-zA-Z]{6,12}$/);
        if(!$('#password').val()){
            showTips('请输入密码！');
            return;
        };
        if(!pwd_reg.test($('#password').val())){
            showTips('密码必须为6-12数字或字母！');
            return;
        };

        $.ajax({
            url: root_path + "/api/user/register",
            type: 'post',
            data: {
//                "recommendPhone":GetQueryString("PhoneNumber"),
            	"recommendPhone":document.referrer.split("=")[1],
                "mobile":$("#tel").val(),
                "password":$('#password').val(),
                "code":$('#code_dx').val(),
                "imgCode":$('#code').val(),
                "imgUrl":root_path+$("#vCode1").find("img").attr("src"),
            },
            success: function(result) {
                img_code();
                console.log(result);
                if(result.code == 1) {
                    showTips("注册成功" , "register_succeed.html")
                } else {
                    showTips(result.message || tipMessage.undefined_msg);
                }
            },
            error: function() {
                showTips(tipMessage.error_msg);
            }
        });
    });
});
